<%@ page language="java" pageEncoding="utf-8"%>
<html>
	<head>
		<title>储值卡信息维护</title>
		<meta name="generator" content="7wx/aop framework">
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<!-- 导入前端系统库 -->
		<script src="/js/jquery-1.4.js"></script>
		      <script type="text/javascript" src="/js/jquery.blockUI.js"></script>
	</head>
	<body leftmargin="0" topmargin="0">
		<table class="layout" cellpadding="0" cellspacing="0">
			<!-- A.标题区 -->
			<tr class="formtitle">
				<td>
					余额合并
				</td>
			</tr>
			<!-- B.表单区 -->
			<tr>
				<td class="formcontainer">
					<form name="outputCardListFrom" id="outputCardListFrom"
						action="/giftcard/transferCard.do_" method="post" target="success">
						<table border="0" cellpadding="2" cellspacing="0" width="480px"
							class="">
							<tr>
								<td align="right">
									转入卡号：
								</td>
								<td>
									<input type="text" name="inputCardNo" id="inputCardNo"
										value="<%=request.getParameter("userSelectedCardNo")%>"
										style="background: #FFFF99; border: #000000 1px solid;"
										size="20" maxLength="20">
								</td>
								<td align="right">
									密码：
								</td>
								<td>
									<input type="password" name="inputCardPassword"
										id="inputCardPassword"
										style="background: #FFFF99; border: #000000 1px solid;"
										size="20" maxLength="20">
								</td>
								<td>
								</td>
							</tr>
							<tr>
								<td>
									&nbsp;
								</td>
							</tr>
							<tr>
								<td align="right">
									转出卡号：
								</td>
								<td>
									<input type="text" name="outputCardNo" id="inputCardNo"
										size="20" maxLength="20">
								</td>
								<td align="right">
									密码：
								</td>
								<td>
									<input type="password" name="outputCardPassword"
										id="outputCardPassword" size="20" maxLength="20">
								</td>
								<td>
									<button onclick="javascript:addGiftCardList();">
										添加
									</button>
								</td>
							</tr>
							<tr>
								<td colspan="100">
									<table align="center" width="400px" id="outputCardList"
										style="border: #000000 1px solid;">
										<tr>
											<td align="center">
												卡号
											</td>
											<td align="center">
												余额
											</td>
											<td>
												&nbsp;
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
			<tr class="buttonbar">
				<td>
					<button onclick="javascript:transferCard();" accesskey="t">
						转账(T)
					</button>
					<button onclick="javascript:window.close();" accesskey="c">
						取消(C)
					</button>
				</td>
			</tr>
		</table>
		<table id="messageArea" width="98%" border="0" align="center"
			cellpadding="0" cellspacing="0" style="display: none">
			<!-- none -->
			<tr>
				<td>
					<iframe onload="this.width = document.body.scrollWidth;"
						height="100" frameborder="0" id="success" name="success">
					</iframe>
				</td>
			</tr>
		</table>
	</body>
	<script type="text/javascript">
      var bufferRemainValue;
      function addGiftCardList(){
         var pattern = /!+|@+|#+|\%+|\^+|&+|\*+|\(+|\)+|\_+|\++|\=+|\-+|\"+|:+|\|+|\\+|\?+|>+|<+|\/+|\'+/;
         var inputCardNoElmentValue = document.getElementById("inputCardNo").value.trim();
         var outputCardNoElementValue = document.getElementById("outputCardNo").value.trim();
         var outputCardPasswordElementValue = document.getElementById("outputCardPassword").value.trim();
         
         if(inputCardNoElmentValue == ""){
            alert("请输入转入卡号！");
            return;
         }
        if(pattern.test(inputCardNoElmentValue)){
             alert("转入卡号中不能包含!@#%^&*()_+=-\":|\?><'字符！");
               return;
         }
         if(outputCardNoElementValue == ""){
            alert("请输入转出卡号！");
            return;
         }
         if(pattern.test(outputCardNoElementValue)){
             alert("转入卡号中不能包含!@#%^&*()_+=-\":|\?><'字符！");
               return;
         }
         if(outputCardPasswordElementValue == ""){
            alert("请输入转出卡密码！");
            return;
         }
         $.ajax({
         	url:"/giftcard/addOutputCard.do_",
         	data:{'inputCardNoElement':inputCardNoElmentValue,
         			'outputCardNoElement':outputCardNoElementValue,
         			'outputCardPasswordElement':outputCardPasswordElementValue},
         	type:"get",
         	cache:false,
         	dataType:"text",
         	error:function(xhr,status,err){
         		alert("系统错误，稍后重试！！");
         	},
         	success:function(data){
         		if(isNaN(data)){
         			alert(data);
         			return;
         		}else{
         			bufferRemainValue = data;
					addOutputCardList();	         		
         		}
         	}
         });
      }
      
      function addOutputCardList(){
         var temps = document.getElementsByName("outputCardList");
         
         for(var i = 0; i < temps.length; i++){
            if(temps[i].value == document.getElementById("outputCardNo").value.trim()){
               alert("该转出卡已经添加！");
               return;
            }
         }
         var currentTable =  document.getElementById("outputCardList");
         var row = currentTable.insertRow(currentTable.rows.length);
         var col = row.insertCell(0);
         if(currentTable.rows.length % 2 == 0){
            row.style.background = "#CCFFFF";
         }
         
         col.align = "center";
         col.innerHTML = "<input name='outputCardList' value='" +
            document.getElementById("outputCardNo").value.trim()
             + "' style='border: 0px; background: transparent; text-align: center' " 
             + "readOnly='readOnly' size='20'>";
             
         col = row.insertCell(1);
         col.align = "center";
         col.innerHTML =  bufferRemainValue;
         col=row.insertCell(2);
         col.align = "center";
         col.innerHTML = "<button onclick='javascript:delThisRow(this);'>删除</button>";
         
         document.getElementById("outputCardNo").value = "";
         document.getElementById("outputCardPassword").value = "";
      }
      
      function delThisRow(element){
         //alert(element.parentElement.parentElement.rowIndex);
         var currentTable =  document.getElementById("outputCardList");
         currentTable.deleteRow(element.parentElement.parentElement.rowIndex);
         var opRows = currentTable.rows;
         for(var i = 1; i < opRows.length; i++){
            if(i%2!=0){
               opRows[i].style.background = "#CCFFFF";
            }else{
               opRows[i].style.background = "";
            }
         }
      }
      
      function transferCard(){
         if(document.getElementById("inputCardNo").value == ""){
            alert("转入卡号不能为空！");
            return;
         }
         if(document.getElementById("inputCardPassword").value == ""){
            alert("转入卡密码不能为空！");
            return;
         }
         outputCardListFrom.submit();
         $.blockUI({message:"<h5>正在处理请稍候...</h5>",css:{ backgroundColor: '#0000FF', color: '#FFEBCD' }});
      }
      

//返回后台控制器的信息
function callbackFunction(state,targetId){
	//显示提示信息
	if(state==1){
		alert(targetId);
		window.close();
		window.opener.location.href=window.opener.location.href; 
	}
	if(state==0){
		$.unblockUI();
		alert(targetId);
		return;
	}
}
   </script>
</html>